<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Example: Custom controls - jWYSIWYG</title>
<link rel="stylesheet" type="text/css" href="../lib/blueprint/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="../lib/blueprint/print.css" media="print" />
<!--[if lt IE 8]><link rel="stylesheet" href="../lib/blueprint/ie.css" type="text/css" media="screen, projection" /><![endif]-->
<link rel="stylesheet" href="../../jquery.wysiwyg.css" type="text/css"/>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type="text/javascript" src="../../jquery.wysiwyg.js"></script>
<script type="text/javascript">
(function($) {
	$(document).ready(function() {
		$("textarea").wysiwyg({
			rmUnusedControls: true,
			controls: {
				bold: { visible : true },
				html: { visible : true },
				insertOrderedList: { visible : true },
				removeFormat: { visible : true }
			}
		});

		$("input[name=add]").click(function () {
			$("textarea").wysiwyg("addControl", "quote", {
				groupIndex: 2,
				icon: './../tests/images/quote02.gif',
				tooltip: 'Quote',
				tags: ['blockquote'],
				exec: function () {
					var range	= this.getInternalRange(),
						common	= range.commonAncestorContainer,
						blockquote = this.dom.getElement("blockquote");

					// if a text node is selected, we want to make the wrap the whole element, not just some text
					if (common.nodeType === 3) {
						common = common.parentNode;
					}

					if (blockquote && $(blockquote).hasClass("quote")) {
						$(common).unwrap();
					}
					else {
						if ("body" !== common.nodeName.toLowerCase()) {
							$(common).wrap("<blockquote class='quote' />");
						}
					}
				},
				callback: function (event, Wysiwyg) {
					alert("callback triggered!");
				}
			});
		});

		$("input[name=makeBold]").click(function () {
			$("textarea").wysiwyg("triggerControl", "bold");
		});
	});
})(jQuery);
</script>
</head>
<body><div class="container">
	<h1>jWYSIWYG</h1>
	<h2>Example: Custom controls</h2>

	<input type="button" value="Add new control" name="add"/>
	<input type="button" value="Make selected text bold" name="makeBold"/>

	<textarea name="text"></textarea>

	<hr/>
	<a href="index.html">Index</a>
</div></body>
</html>